home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Grafik / Misc / ImageEnginer / ARexx / Batch / Noise.ieb < prev    next >
Encoding:
Text File  |  1997-02-02  |  3.9 KB  |  149 lines

  1. /*
  2. ** $VER: Noise.ieb 1.1, IE Arexx script
  3. ** Image Engineer Batch Processing script
  4. ** Copyright © by Patrik M Nydensten
  5. ** 25/1 1997 Stockholm/Sweden
  6. **
  7. ** Add noise to image.
  8. */
  9.  
  10. options results
  11. signal on error
  12.  
  13. parse arg input command
  14. input = upper(strip(input))
  15. address 'IMAGEENGINEER'
  16.  
  17. select  /* Required batch script commands */
  18.   when input = 'INFO' then    return get_info()
  19.   when input = 'CONFIG' then  return get_config(command)
  20.   when input = 'PROCESS' then return process_image(command)
  21.   otherwise do
  22.     'REQUEST' '"Failure in call to batch script!"' '" Quit "'
  23.     return '<ERROR>'
  24.   end
  25. end
  26.  
  27. exit 0
  28.  
  29. /* Required "Get_info" procedure  ------------------------------------ */
  30. /* S = SECONDARY, A = ALPHA, 1 = Single file, 2 = Multiple files       */
  31.  
  32. get_info:
  33.   back = 'OK'
  34. return back
  35.  
  36. /* Required "Get_config" procedure  ---------------------------------- */
  37.  
  38. get_config:
  39.   parse arg '"'command'"'
  40.  
  41.   Affect=50 ; Addit=50
  42.  
  43.   if command ~= '' then parse var command '#'CalcType '#'AB '#'BB '#'CB Affect '#'Noise Addit '#'Dist
  44.  
  45.   'IE_TO_FRONT'
  46.  
  47.   form = 'FORM "Noise" " OK | Cancel "'
  48.  
  49.   if command = '' then form = form||' CYCLE,"Components:","Intensity, Hue, Saturation|Red, Green, Blue",0',
  50.   ' CHECKBOX,"Intensity / Red",1',
  51.   ' CHECKBOX,"Hue / Green",0',
  52.   ' CHECKBOX,"Saturation / Blue",0'
  53.  
  54.   form = form||' INTEGER,"Noise (%)",0,100,'Affect',SLIDER'
  55.  
  56.   if command = '' then form = form||' CYCLE,"Noise type:","Random|Additive",0',
  57.   ' CYCLE,"Additive distribution:","Simple|Gaussian",0'
  58.  
  59.   form = form||' INTEGER,"Additive amount",0,100,'Addit',SLIDER'
  60.  
  61.   if command = '' then do
  62.     form
  63.     parse var result ok CalcType AB BB CB Affect Noise Dist Addit
  64.     if ok = 0 then return '<ERROR>'
  65.   end
  66.   else do
  67.     form
  68.     parse var result ok Affect Addit
  69.     if ok = 0 then return '<ERROR>'
  70.  
  71.     CalcType = 'none'
  72.     AB='none';BB='none';CB='none'
  73.     Noise = 'none'
  74.     Dist = 'none'
  75.   end
  76.  
  77.   if (AB=0&BB=0&CB=0) then return '<ERROR>'
  78.  
  79.   back = '#'CalcType '#'AB '#'BB '#'CB Affect '#'Noise Addit '#'Dist
  80. return back
  81.  
  82. /* Required "Process_image" procedure  ------------------------------- */
  83.  
  84. process_image:
  85.   parse arg '"'src_image'"' '"'dst_image'"' '"'options'"'
  86.   parse var options '#'CalcType '#'AB '#'BB '#'CB Affect '#'Noise Addit '#'Dist
  87.  
  88.   'OPEN' '"'src_image'"' '24'
  89.   if (RC ~= 0) then do
  90.     'IE_TO_FRONT'
  91.     'REQUEST' '"Failed to load image:' d2c(10)||src_image'"' '" OK "'
  92.     return '<ERROR>'
  93.   end
  94.   else LoadImage = result
  95.  
  96.   if CalcType = 0 then do
  97.     Calc = ''
  98.     if AB = 1 then Calc = 'INTENSITY'
  99.     if BB = 1 then Calc = 'HUE'
  100.     if CB = 1 then Calc = 'SATURATION'
  101.   end
  102.   else do
  103.     Calc = ''
  104.     if AB = 1 then Calc = 'RED'
  105.     if BB = 1 then Calc = 'GREEN'
  106.     if CB = 1 then Calc = 'BLUE'
  107.   end
  108.  
  109.   if Dist = 0 then Dist = 'SIMPLE'
  110.   else Dist = 'GAUSSIAN'
  111.  
  112.   if Noise = 0 then 'NOISE' LoadImage Affect strip(Calc) 'RANDOM'
  113.   else 'NOISE' LoadImage Affect strip(Calc) 'ADDITIVE' Addit Dist
  114.   OutputImage = result
  115.   'CLOSE' LoadImage
  116.  
  117.   if getclip('cfg_save_frmt')='' then setclip('cfg_save_frmt','ILBM CmpByteRun1')
  118.   'SAVE_DATA' OutputImage '"'dst_image'"' '"'getclip('cfg_save_frmt')'"'
  119.   if (RC ~= 0) then do
  120.     'IE_TO_FRONT'
  121.     'REQUEST' '"Failed to save image:' d2c(10)||dst_image'"' '" OK "'
  122.     return '<ERROR>'
  123.   end
  124.   'CLOSE' OutputImage
  125.  
  126.   back = 'OK'
  127. return back
  128.  
  129. /* Internal procedures  ---------------------------------------------- */
  130.  
  131. /*******************************************************************/
  132. /* This is where control goes when an error code is returned by IE */
  133. /* It puts up a message saying what happened and on which line     */
  134. /*******************************************************************/
  135.  
  136. error:
  137. if RC=5 then do
  138.     IE_TO_FRONT
  139.     LAST_ERROR
  140.     'REQUEST "'||RESULT||'"'
  141. end
  142. else do
  143.     IE_TO_FRONT
  144.     LAST_ERROR
  145.     'REQUEST "Error detected!!!'||D2C(10)||'Image Engineer error message is as follows'||D2C(10)||result||D2C(10)||'Script failed on line '||SIGL||'"' 'Doh!'
  146. end
  147.  
  148. return '<ERROR>'
  149.